package com.gzs.learn.payment.inf.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 定义系统异常返回码
 *
 * @author guanzhisong
 * @date 2021-08-10
 */
@Getter
public enum PaymentResponseCodeEnum {
    SERIAL_ERROR(1001, "获取支付流水号失败"),

    SERIAL_REFUND_ERROR(1002, "获取退款流水号失败"),

    SYS_ERROR(-1, "系统未知异常"),

    ;

    private static final Map<Integer, PaymentResponseCodeEnum> HOLDER_MAP = new HashMap<>();
    static {
        for (PaymentResponseCodeEnum e : values()) {
            HOLDER_MAP.put(e.getCode(), e);
        }
    }

    private final int code;
    private final String desc;

    PaymentResponseCodeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static PaymentResponseCodeEnum convert(int code) {
        return HOLDER_MAP.get(code);
    }
}
